<div class="list-box">
    <div class="nav">
        <ul>
            <li>方案类型管理</li>
            <li>/</li>
            <li>方案类型列表</li>
        </ul>
    </div>
    <div class="search">
        <form>
            方案类型标题 : <input type="text">
            <input type="button" class="btn" value="搜索">
        </form>
    </div>
    <div class="toolbar">
        <input type="button" class="btn" value="新增类型" id="addBtn">
        <input type="button" class="btn" value="删除类型" onclick="deletes()">
    </div>
    <div>
        <table id="solutionTypeTable"></table>
    </div>
</div>
<script>
    var updateId;//保存修改编号
    $(function () {
        $.get("/web/solutionType", {op: "list"}, function (data) {
            var table = $("#solutionTypeTable");
            table.empty();
            table.append(`<tr>
                <th><input type="checkbox" id="check" onclick="checkAll()"></th>
                <th>编号</th>
                <th>类型标题</th>
                <th>添加时间</th>
                <th>最后一次修改时间</th>
                <th>操作</th>
            </tr>`);
            for (let i = 0; i < data.length; i++) {
                table.append(`<tr>
                <td><input type="checkbox" value="${data[i].solutionTypeId}"></td>
                <td>${data[i].solutionTypeId}</td>
                <td>${data[i].solutionTypeTitle}</td>
                <td>${data[i].createTime}</td>
                <td>${data[i].modifyTime}</td>
                <td>
                    <input type="button" class="btn" value="编辑" onclick="editSolutionType(${data[i].solutionTypeId})">
                    <input type="button" class="btn" value="删除" onclick="deleteSolutionType(${data[i].solutionTypeId})">
                </td>
            </tr>`);
            }
        });
        //添加页面跳转
        $("#addBtn").click(function () {
            $("#content").load("solutionType/solution-type-add.html");
        });
    });

    //全选操作
    function checkAll() {
        var flag = $("#check").prop("checked");
        $("input[type='checkbox']").prop("checked", flag);
    }

    //批量删除
    function deletes() {
        if (confirm("您确定要删除吗？")) {
            var param = "op=deleteBatch";
            var inputs = $("input[type='checkbox']:not(#check)");
            for (let i = 0; i < inputs.length; i++) {
                if ($(inputs[i]).prop("checked")) {
                    param += "&solutionTypeId=" + $(inputs[i]).val();
                }
            }
            $.get("/web/solutionType", param, function (data) {
                alert(data);
                $("#content").load("solutionType/solution-type-list.html");
            });
        }
    }

    //删除操作
    function deleteSolutionType(id) {
        if (confirm("您确定要删除吗？")) {
            $.get("/web/solutionType", {op: "delete", solutionTypeId: id}, function (data) {
                alert(data);
                $("#content").load("solutionType/solution-type-list.html");
            });
        }
    }

    //编辑操作
    function editSolutionType(id) {
        updateId = id;
        $("#content").load("solutionType/solution-type-update.html");
    }
</script>
